package leetcode.editor.cn;

import java.util.HashSet;
import java.util.Set;

/**
 * 无重复字符的最长子串
 * @author qulq
 * @date 2024-07-07
 */
public class T3_LongestSubstringWithoutRepeatingCharacters{
	 public static void main(String[] args) {
	 	 //测试代码
	 	 Solution solution = new T3_LongestSubstringWithoutRepeatingCharacters().new Solution();
	 }
	 
//力扣代码
//leetcode submit region begin(Prohibit modification and deletion)
class Solution {
	public int lengthOfLongestSubstring(String s) {
		char[] chars = s.toCharArray();
		Set<Character> set = new HashSet<>();
		int ans = 0;
		for (int left = 0, right = 0; right < chars.length; right++) {
			while (set.contains(chars[right])) {
				set.remove(chars[left++]);
			}
			set.add(chars[right]);
			ans = Math.max(ans, right - left + 1);
		}
		return ans;
	}
}
//leetcode submit region end(Prohibit modification and deletion)

}